import {defineStore} from 'pinia'
import {postUsersListData, deleteUserById, newUserData, editUserData} from '@/service/main/system/system'

interface ISystemState {
  usersList: any[]
  usersTotalCount: number
}

const useSystemStore = defineStore("system", {
  state: ():ISystemState => ({
    usersList: [],
    usersTotalCount: 0
  }),
  actions: {
    async postUsersListAction(queryInfo:any) {
      const usersListResult = await postUsersListData(queryInfo)
      const {totalCount, list} = usersListResult.data
      this.usersTotalCount = totalCount
      this.usersList = list
    },
    async deleteUserByIdActition(id:number) {
      const res = await deleteUserById(id)
      // console.log(res)
      this.postUsersListAction({offset: 0, size: 10})
    },
    async newUserDataAction(userInfo:any) {
      const res = await newUserData(userInfo)
      // console.log(res)
      this.postUsersListAction({offset: 0, size: 10})
    },
    async editUserDataAction(id:number, userInfo:any) {
      const res = await editUserData(id,userInfo)
      console.log(res)
      this.postUsersListAction({offset: 0, size: 10})
    }
  }
})
export default useSystemStore